package netty.demo.nio.byteBuffer;

import lombok.extern.slf4j.Slf4j;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

import static netty.demo.nio.byteBuffer.ByteBufferUtil.debugAll;


/**
 * @author Zed
 * @description 分散读取
 * @date 2022/10/22 16:21
 */
@Slf4j
public class testScatteringRead {
    public static void main(String[] args) {
        try {
            FileChannel channel = new RandomAccessFile("words.txt", "r").getChannel();
            ByteBuffer b1 = ByteBuffer.allocate(3);
            ByteBuffer b2 = ByteBuffer.allocate(3);
            ByteBuffer b3 = ByteBuffer.allocate(5);
            channel.read(new ByteBuffer[]{b1, b2, b3});
            b1.flip();
            b2.flip();
            b3.flip();
            debugAll(b1);
            debugAll(b2);
            debugAll(b3);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
